<!--sidebar-menu-->
<div id="sidebar" class="clearfix"><!-- <a href="#" class="visible-phone"><i class="icon icon-home"></i> Dashboard</a> -->
  <ul style="display: block;">
  {% include "common/menu.html" %}
  </ul>
</div>
<!--end sidebar-menu-->

<div id="content">
  
    <div class="container-fluid" style="padding: 0;">
      <div class="widget-box tab-tabs" >
          <div class="widget-title">
            <ul class="nav nav-tabs">
                {% include "common/tab.html" %}
            </ul>
          </div>
          <div class="widget-content tab-content">
            <div id="tab1" class="tab-pane active">
              <div class="container-fluid">
                <div class="row-fluid" style="margin: 20px 0;overflow: hidden;">
                  <form id="fiamlyform" class="form-search">
                    <span class="find-search pull-right">
                        <a class="date-calendar pull-right"><i class=" icon-calendar"></i> <input id="mydate"  placeholder="请输入日期"  value="" style="height: 34px;"></a>
                    </span>
                  </form>
                </div>
                
                <div class="row-fluid">
                  <table id="tableList" class="table with-check table-purple">
                    <thead>
                      <tr>
                        <th>时间</th>
                        <th>登录用户</th>
                        <th>登录IP</th>
                        <th>类型</th>
                      </tr>
                    </thead>
                    <tbody>

                    </tbody>
                  </table>
                </div>

                {% include "common/pagination.html" %}
              </div>
            </div>

            
         </div>
        </div>
    
    </div>
            
    
</div>


<script src="{{static_url('web/js/daterangepicker.jQuery.js')}}"></script>
<link rel="stylesheet" href="{{static_url('web/css/ui.daterangepicker.css')}}">
<script type="text/javascript">

    $(function(){
        giftlist();
    });


    $('#mydate').daterangepicker({
                presetRanges:[
                    //{text:'最近一周', dateStart:'yesterday-7days', dateEnd:'yesterday' },
                    //{text:'最近一月', dateStart:'yesterday-1month', dateEnd:'yesterday' },
                    //{text:'最近一年', dateStart:'yesterday-1year', dateEnd:'yesterday' }
                ],
                presets:{
                    dateRange:'自定义时间'
                },
                rangeStartTitle:'起始日期',
                rangeEndTitle:'结束日期',
                nextLinkText:'下月',
                prevLinkText:'上月',
                doneButtonText:'确定',
                cancelButtonText:'取消',
                earliestDate:'',
                latestDate:Date.parse('today'),
                constrainDates:true,
                rangeSplitter:'-',
                dateFormat:'yy-mm-dd',
                closeOnSelect:false,
                onOpen:function(){
                    $('.ui-daterangepicker-dateRange').click().parent().hide();
                    $('.ui-daterangepickercontain').css({left:($('#mydate').offset().left-325)+'px'});
                },
                onClose:function(){
                    giftlist();
                }
            }
    );

    function giftlist(index){
        var a=$('#mydate').val();
        var startTime= a.substring(0,10);
        var endTime= a.substring(12,23);
        var data={};
        data.startTime=startTime;
        data.endTime=endTime;
        data.page=index||1;
        data.pageSize=global.pageSize;
        $.ajax({
            type: "POST",
            data: data,
            url: '/ajax/loginJournal',
            dataType: 'json',
            success: function (res) {
                var data = res.data;
                $('#tableList tbody').html('');
                var count=document.getElementById('count');
                count.innerHTML=data.count;
                for(var i=0;i<data.list.length;i++){
                    $('#tableList tbody').append(gethtml(data.list[i]));
                }
                if(!index||index==0){
                    utilsPagination("#pagination",data.count,global.pageSize,function(page_index,jq){
                        page_index+= 1;
                        giftlist(page_index);
                    });
                }
            }
        })
    }

    function gethtml(data){
        var html='';
        html+='<tr><td>'+data.createTime+'</td><td>'+data.userName+'</td><td>'+data.ip+'</td>';
        if(data.loginType==0){
            html+='<td>未知</td></tr>'
        }
        if(data.loginType==1){
            html+='<td>登录</td></tr>'
        }
        if(data.loginType==2){
            html+='<td>退出</td></tr>'
        }
        return html;
    }
</script>

